import 'package:flutter/material.dart';

import 'package:junyeyishu/utils/utils.dart';
import 'package:junyeyishu/widgets/QGWidget.dart';

class QGMineOrderCell extends StatefulWidget {
  dynamic data;
  QGMineOrderCell({super.key, this.data});
  @override
  State<QGMineOrderCell> createState() => QGMineOrderCellState();
}

class QGMineOrderCellState extends State<QGMineOrderCell> {
  @override
  Widget build(BuildContext context) {
    var num = widget.data?["goods_num"] ?? widget.data?["good_num"];
    // var type = widget.data?["type"] ?? widget.data?["type"];

    if (num is String) {
      num = "x$num";
    } else {
      num = "#${widget.data?["nft_no"]}/${widget.data?["total"]}";
    }


    return Container(
      margin: EdgeInsets.only(top: 10.rpx, left: 10.rpx, right: 10.rpx),
      padding: EdgeInsets.all(10.rpx),
      decoration: BoxDecoration(
        borderRadius: BorderRadius.circular(6.rpx),
        color: Color(0xFF232A32),
      ),
      child: Column(
        children: [
          Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              widget.data?["ttype"] != 4?
              Text('订单编号:${widget.data?["out_trade_no"]}',style: TextStyle(fontSize: 13,color: Color(0XFF989EA4))):SizedBox(),
              widget.data?["ttype"] != 4? buildState():Text(
             '${widget.data?["types"]}成功',
          style: TextStyle(
              color: const Color(0xFF4AE3FF),
              fontSize: 12.rpx,
              fontWeight: FontWeight.normal),
        )
            ],
          ),
           if( widget.data?["ttype"] != 4)

          SizedBox(height: 20.rpx,),
        Row(
          children: [
            ClipRRect(
              borderRadius: BorderRadius.circular(4.rpx),
              child: QGImage(
                  url: widget.data?["thumb_img"],
                  width: 72.rpx,
                  height: 72.rpx),
            ),
            SizedBox(width: 10.rpx),
            Expanded(
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Text(
                          widget.data?["order_name"] ?? widget.data?["nft_name"],
                          style: TextStyle(
                              color: Color(0xFFffffff),
                              fontSize: 14.rpx,
                              fontWeight: FontWeight.normal),
                        ),
                        if(widget.data?["ttype"] != 4)
                      Text(
                        '￥${widget.data?["total_fee"] ?? widget.data?["price"]}',
                        style: TextStyle(
                            color: Color(0xFF989EA4),
                            fontSize: 12.rpx,
                            fontWeight: FontWeight.bold),
                      ),
                      SizedBox(height: 5.rpx,),
                     widget.data?["ttype"] != 4?
                   Text(
                        num,
                        style: TextStyle(
                            color: const Color(0xff999999),
                            fontSize: 12.rpx,
                            fontWeight: FontWeight.normal),
                      ): Text(
                        'x1',
                        style: TextStyle(
                            color: const Color(0xff999999),
                            fontSize: 12.rpx,
                            fontWeight: FontWeight.normal),
                      )
                  // Row(
                  //   mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  //   children: [
                  //    ,
                  //     // Flexible(
                  //     //   child: Text(
                  //     //     widget.data?["created"] ?? "",
                  //     //     style: TextStyle(
                  //     //         color: const Color(0xff999999),
                  //     //         fontSize: 12.rpx,
                  //     //         fontWeight: FontWeight.normal),
                  //     //   ),
                  //     // ),
                  //   ],
                  // ),
                ],
              ),
            ),
          ],
        ),
        SizedBox(height: 20.rpx),

        Row(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: [
            Text(
              '创建时间',
              style: TextStyle(
                  color: const Color(0xff989EA4),
                  fontSize: 13.rpx,
                  fontWeight: FontWeight.normal),
            ),
            Text(
              widget.data?["created"] ?? "",
              style: TextStyle(
                  color: const Color(0xffFFFFFF),
                  fontSize: 13.rpx,
                  fontWeight: FontWeight.normal),
            )
          ],
        ),
        if( widget.data?["type"] == 1)
        SizedBox(height: 20.rpx,),
        if(widget.data?["ttype"] == 0 &&widget.data?["type"] == 1 || widget.data?["ttype"] == 1 &&widget.data?["type"] == 1)
        Row(
          mainAxisAlignment: MainAxisAlignment.end,
          children: [
            // Container(
            //   child:Text(
            //     '取消',
            //     style: TextStyle(
            //         color: const Color(0xff989EA4),
            //         fontSize: 13.rpx,
            //         fontWeight: FontWeight.normal),
            //   ),
            // ),
            // SizedBox(width: 20.rpx,),
            Container(
              width: 90.rpx,
              alignment: Alignment.center,
              height: 35.rpx,
              decoration: BoxDecoration(
                color: Color(0XFF111111),
                borderRadius: BorderRadius.circular(30)
              ),
              child:Text(
                '去支付',
                style: TextStyle(
                    color: const Color(0xffFFFFFF),
                    fontSize: 13.rpx,
                    fontWeight: FontWeight.normal),
              ),
            )
          ],
        )
        // buildState(),
      ]),
    );
  }

  buildState() {
    var img;
    Widget text = Container(); 

    if(widget.data?["ttype"]==0 ||widget.data?["ttype"]==1){
      switch (widget.data?["type"]) {
      case 0:
        img = "mine_order_success";
        text = Text(
          '转入成功',
          style: TextStyle(
              color: const Color(0xFF4AE3FF),
              fontSize: 12.rpx,
              fontWeight: FontWeight.normal),
        );

        break;
      case 1:
        img = "mine_order_waiting";
        text = Text(
          '待付款',
          style: TextStyle(
              color: const Color(0xFF4AE3FF),
              fontSize: 12.rpx,
              fontWeight: FontWeight.normal),
        );
        break;
      case 2:
        img = "mine_order_cancel";
        text = Text(
          '已取消',
          style: TextStyle(
              color: const Color(0xff999999),
              fontSize: 12.rpx,
              fontWeight: FontWeight.normal),
        );
        break;
    }
    }else{
      if(widget.data?["ttype"]==2){

      }
    }

    



    return Row(
      mainAxisAlignment: MainAxisAlignment.spaceBetween,
      children: [
        Container(
          padding: EdgeInsets.symmetric(vertical: 3.rpx),
          // decoration: BoxDecoration(
          //   borderRadius: BorderRadius.circular(4.rpx),
          //   color: Color(0xFFF8F8F6),
          // ),
          child: Row(
            children: [
              // QGImage(asset: img),
              // SizedBox(width: 6.rpx),
              text,

              // Text(
              //   '等待付款',
              //   style: TextStyle(
              //       color: const Color(0xffE61212),
              //       fontSize: 11.rpx,
              //       fontWeight: FontWeight.normal),
              // ),
              // SizedBox(width: 8.rpx),
              // Text(
              //   '00:05:00',
              //   style: TextStyle(
              //       color: const Color(0xffffffff),
              //       fontSize: 12.rpx,
              //       fontWeight: FontWeight.normal),
              // ),
            ],
          ),
        ),
        widget.data?["type"] == 1
            ? QGImage(asset: "mine_info_arrow")
            : Container(),
      ],
    );
  }
}
